package ex_from_web;


/**
 * Java thread example
 * Creating two threads which will run parallel
 * (rather than sequentially one by one)
 */

/**
 * To declare a thread class have to extend class Thread
 * or implement Runnable interface,
 * and implement run() method
 */
class SimpleThread extends Thread {
    String name;
    
    public SimpleThread(String name) {
        this.name = name;
    }
    
    //Code inside run() method will be executed when 
    //thread has been started
    public void run() {
        for (int i=0; i<10; i++) {
            System.out.println(name + " thread:" + i);
        }
    }
}

public class ParallelThreads {

    public static void main(String[] args) {
        SimpleThread t1 = new SimpleThread("t1");
        SimpleThread t2 = new SimpleThread("t2");
        //start() method is used to run the thread.
        //It will invoke run() method
        t1.start(); 
        t2.start();
    }

}